<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!-- saved from url=(0075)http://www.cs.duke.edu/courses/cps108/current/assign/03_slogo/commands2.php -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>CompSci 308 : Spring 2013</title>
 <meta http-equiv="content-language" content="en-us">
 
 <meta http-equiv="content-style-type" content="text/css">
 <meta name="author" content="Robert C. Duvall">
 <meta name="robots" content="all">
 <link href="./HelpDocument_files/horizontal.css" type="text/css" rel="stylesheet" media="screen">
 <link href="./HelpDocument_files/common.css" type="text/css" rel="stylesheet" media="screen">
 <link href="./HelpDocument_files/compsci308.css" type="text/css" rel="stylesheet" media="screen">
 <link href="./HelpDocument_files/print.css" type="text/css" rel="stylesheet" media="print">
<style type="text/css"></style></head>

<body class=" hasGoogleVoiceExt">
<div class="contentPane">
  <div class="header">
    <table>
      <tbody><tr>
        <td class="left">CompSci 308<br>Spring 2013</td>
        <td class="right">Software Design and Implementation</td>
      </tr>
    </tbody></table>
  </div>
	

  <div class="mainBody">

<h3><a href="http://www.cs.duke.edu/courses/cps108/current/assign/03_slogo/index.php">SLogo</a>  Basic Commands</h3>

<h4 align="left">Notes</h4>
Triple clicking on a line in the command history will re-run the command.<br />
Click the manual control button to move the turtle with arrow keys (sometimes you have to click it twice)

<h4 align="left">Basic Syntax</h4>
<TABLE BORDER="1">
<TR>
  <TH>Token</TH>
  <TH>Syntax</TH>
  <TH>Semantics</TH>
  <TH>Examples</TH>
</TR>
<TR>
  <TD><B>Constant</B></TD>
  <TD><DIV align="center"><code>[-]?[0-9]+</code></DIV></TD>
  <TD>any whole valued number<br />
      note, to avoid potential ambiguity in parsing there should not be a space between the negative sign and the value
  </TD>
  <TD><DIV align="right">
        <code>50</code><BR />
        <code>-13</code>
      </DIV>
  </TD>
</TR>
<TR>
  <TD><B>Variable</B></TD>
  <TD><DIV align="center"><code>:[a-zA-z]+</code></DIV></TD>
  <TD>any word preceded by a colon, :<br />
    note, if a variable name is used that has not previously been given a value, return a default value (i.e., 0)</TD>
  <TD><DIV align=right>
    <code>:distance</code><BR />
    <code>:side</code></DIV>
  </TD>
</TR>
<tr>
  <td><b>Command</b></td>
  <td><div align="center"><code>[a-zA-z_]+(\?)?</code></div></td>
  <td>any word can be a command-name<br />
    note, all commands return a numeric value<br />
    note, built-in commands are given below and  user-defined commands cannot reuse those names</td>
  <td><div align="right"> <code>forward</code><br />
    <code>fd</code></div></td>
</tr>
<TR>
  <TD><strong>List</strong></TD>
  <TD><div align="center"><code>[ <br />
    ]</code></div></TD>
  <TD>these brackets enclose a list of zero or more commands or variables<br />
    note, to make parsing easier, these will always be separated from other tokens by spaces</TD>
  <TD><code>[ fd 50 rt 90 ]</code></TD>
</TR>
</TABLE>

<H4>Turtle Commands</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name(s)</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>FORWARD <em>pixels</em><br>
    FD <em>pixels</em></TD>
  <TD>moves  turtle forward in its current heading by <em>pixels</em> distance<br />
    returns the value of <em>pixels</em></TD>
</TR>
<TR>
  <TD>BACK <em>pixels</em><br>
    BK <em>pixels</em></TD>
  <TD>moves  turtle backward in its current heading by <em>pixels</em> distance<br />
    returns the value of <em>pixels</em></TD>
</TR>
<TR>
  <TD>LEFT <em>degrees</em><br>
    LT <em>degrees</em></TD>
  <TD>turns  turtle counterclockwise by <em>degrees</em> angle<br />
    returns the value of <em>degrees</em></TD>
</TR>
<TR>
  <TD>RIGHT <em>degrees</em><br>
    RT <em>degrees</em></TD>
  <TD>turns  turtle clockwise by <em>degrees</em> angle<br />
    returns the value of <em>degrees</em></TD>
</TR>
<tr>
  <td>SETHEADING <em>degrees</em><br />
    SETH <em>degrees</em></td>
  <td>turns  turtle to an absolute heading<br />
    returns number of degrees moved </td>
</tr>
<TR>
  <TD>TOWARDS <em>x</em> <em>y </em></TD>
  <TD>turns  turtle to face the point (<em>x</em>, <em>y</em>), where (0, 0) is the center of the screen<br />
    returns the number of degrees  turtle turned</TD>
</TR>
<tr>
  <td>SETXY <em>x</em> <em>y</em><br />
    GOTO <em>x</em> <em>y</em></td>
  <td>moves  turtle to an absolute screen position, where (0, 0) is the center of the screen<br />
    returns number of pixels moved </td>
</tr>
<TR>
  <TD>PENDOWN<br>PD</TD>
  <TD>puts  pen down such that when the turtle moves, it leaves a trail<br />
    returns 1</TD>
</TR>
<TR>
  <TD>PENUP<br>PU</TD>
  <TD>puts  pen up such that when the turtle moves, it does not leave a trail<br />
    returns 0</TD>
</TR>
<TR>
  <TD>SHOWTURTLE<br>ST</TD>
  <TD>makes  turtle visible<br />
    returns 1</TD>
</TR>
<TR>
  <TD>HIDETURTLE<br>HT</TD>
  <TD>makes  turtle invisible<br />
    returns 0</TD>
</TR>
<TR>
  <TD>HOME</TD>
  <TD>moves  turtle to the center of the screen (0 0)<br />
    returns the distance turtle moved</TD>
</TR>
<TR>
  <TD>CLEARSCREEN<br>CS</TD>
  <TD>erases  turtle's trails and sends it to the home position<br />
    returns the distance turtle moved</TD>
</TR>
</TABLE>


<H4>Turtle Queries</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>XCOR</TD>
  <TD>returns the turtle's X coordinate in pixels from the center of the screen</TD>
</TR>
<TR>
  <TD>YCOR</TD>
  <TD>returns the turtle's Y coordinate in pixels from the center of the screen</TD>
</TR>
<tr>
  <td>HEADING</td>
  <td>returns the turtle's heading in degrees</td>
</tr>
<tr>
  <td>PENDOWN?<br />
    PENDOWNP</td>
  <td>returns 1 if turtle's pen is down, 0 if it is up</td>
</tr>
<tr>
  <td>SHOWING?<br />
    SHOWINGP</td>
  <td>returns 1 if turtle is showing, 0 if it is hiding</td>
</tr>
</TABLE>


<H4>Math Operations</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>SUM <em>value1</em> <em>value2</em><br />
    + <em>value1</em> <em>value2</em></TD>
  <TD>returns sum of <i>value1</i> and <i>value2</i></TD>
</TR>
<TR>
  <TD>DIFFERENCE <em>value1</em> <em>value2</em><br />
    - <em>value1</em> <em>value2</em></TD>
  <TD>returns difference of <i>value1</i> and <i>value2</i></TD>
</TR>
<TR>
  <TD>PRODUCT <em>value1</em> <em>value2</em><br />
    * <em>value1</em> <em>value2</em></TD>
  <TD>returns product of <i>value1</i> and <i>value2</i></TD>
</TR>
<TR>
  <TD>QUOTIENT <em>value1</em> <em>value2</em><br />
    / <em>value1</em> <em>value2</em></TD>
  <TD>returns integer quotient of <i>value1</i> and <i>value2</i></TD>
</TR>
<TR>
  <TD>REMAINDER <em>value1</em> <em>value2</em><br />
    % <em>value1</em> <em>value2</em></TD>
  <TD>returns integer remainder on dividing <i> value1</i> by <i>value2</i></TD>
</TR>
<TR>
  <TD>MINUS <em>value</em><br />
    ~ <em>value</em></TD>
  <TD>returns negative of <i>value</i></TD>
</TR>
<TR>
  <TD>RANDOM <em>max</em></TD>
  <TD>returns random non-negative integer strictly less than <em>max</em></TD>
</TR>
</TABLE>


<H4>Boolean Operations</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>LESS? <em>value1</em> <em>value2</em><br />
    LESSP <em>value1</em> <em>value2</em></TD>
  <TD>returns 1  if <em>value1</em> is strictly less than <em>value2</em>, otherwise 0</TD>
</TR>
<TR>
  <TD>GREATER? <em>value1</em> <em>value2</em><br />
    GREATERP <em>value1</em> <em>value2</em></TD>
  <TD>returns 1 if  <em>value1</em> is strictly greater than <em>value2</em>,  otherwise 0</TD>
</TR>
<TR>
  <TD>EQUAL? <em>value1</em> <em>value2</em><br />
    EQUALP <em>value1</em> <em>value2</em></TD>
  <TD>returns 1 if  <em>value1 </em>and <em>value2</em> are equal, otherwise 0</TD>
</TR>
<TR>
  <TD>NOTEQUAL? <em>value1</em> <em>value2</em><br />
    NOTEQUALP <em>value1</em> <em>value2</em> &nbsp;</TD>
  <TD>returns 1 if  <em>value1</em> and  <em>value2</em> are not equal, otherwise 0</TD>
</TR>
<TR>
  <TD>AND <em>test1</em> <em>test2</em></TD>
  <TD>returns 1  if <i>test1</i> and <i>test2</i> are non-zero, otherwise 0</TD>
</TR>
<TR>
  <TD>OR <em>test1</em> <em>test2</em></TD>
  <TD>returns 1 if <i>test1</i> or <i>test2</i> are non-zero, otherwise 0</TD>
</TR>
<TR>
  <TD>NOT <em>test</em></TD>
  <TD>returns 1 if <i>test</i> is 0 and 0 if <i>test</i> is non-zero</TD>
</TR>
</TABLE>

<H4>Variables, Control Structures, and User-Defined Commands</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>MAKE <em>variable</em> <em>value</em><br />
      SET <em>variable</em> <em>value</em></TD>
  <TD>assigns <em>value</em> to <em>variable</em>, creating the variable if necessary<em><br />
  </em>returns <em>value</em></TD>
</TR>
<TR>
  <TD>REPEAT <em>value</em> [ <em>command(s)</em> ]</TD>
  <TD>runs the <em>commands</em> given in the  list <em>value</em> number of times<br />
    returns the value of the final command executed<br />    
    note, the value of the current iteration, starting at 1, is automatically assigned to the variable <em>:repcount</em> so that it can be accessed by the <em>commands</em>  </TD>
</TR>
<TR>
  <TD>IF <em>value</em> [ <em>command(s)</em> ]</TD>
  <TD>if <em>value</em> is not 0, runs the <em>commands</em> given in the  list<br />
    returns the value of the final command executed</TD>
</TR>
<TR>
  <TD>IFELSE <em>value</em> <br />
    [ <em>trueCommand(s)</em> ] <br />
    [ <em>falseCommand(s)</em> ]</TD>
  <TD>if <i> value</i> is not 0, runs the <em>trueCommands</em> given in the first  list, otherwise runs the <em>falseCommands</em> given in the second  list<br />
    returns the value of the final command executed</TD>
</TR>
<TR>
  <TD>TO <em>commandName<br />
  </em> [ <em>parameter(s)</em> ]<br />
[ <em>command(s)</em> ]</TD>
  <TD>assigns  <em>commands</em> given in the second list to <em>commandName</em> using  <em>parameters</em> given in first list as variables<br />
    when <em>commandName</em> is used later in a program,  any given values are assigned to variables that can be accessed when  the command list is run<br />
    returns 1 if command is successfully defined, otherwise 0</TD>
</TR>
</TABLE>


<h3>Additional Commands</h3>

<H4>Turtle Commands</H4>
<TABLE BORDER="1">
<TR>
  <TH>Name(s)</TH>
  <TH>Description</TH>
</TR>
<TR>
  <TD>SETPENDESIGN <em>String</em><br>
    SETPD <em>solid</em></TD>
  <TD>sets design of the pen to that represented by design_name <em>solid or dashed</em> <br />
    returns 1 if it worked </TD>
</TR>
<TR>
  <TD>TOGGLEGRID <br>
    TG </TD>
  <TD>turns the grid on and off/>
    returns 1 if it worked</TD>
</TR>
<TR>
  <TD>SETGRIDSIZE <em>pixels</em><br>
    SETGS <em>pixels</em></TD>
  <TD>sets the grid line density to <em>pixels</em> angle<br />
    returns the value of <em>degrees</em></TD>
</TR>
<TR>
  <TD>CHANGEBG <em>image path</em><br></TD>
  <TD>changes background image to the image at path</em></TD>
</TR>
<tr>
  <td>REM <br />
    REMBG </td>
  <td>removes current background</td>
</tr>
<TR>
  <TD>CREATE <em>turtle id</em></TD>
  <TD>creates a turtle with id</TD>
</TR>
<tr>
  <td>SAVE <em>[ filepath ]</em></td>
  <td>save the command history to the filepath, returns 1 if it works </td>
</tr>
<TR>
  <TD>LOAD<br>[ filepath ]</TD>
  <TD>loads and executes a file of slogo commands<br />
    returns 1 if it worked</TD>
</TR>
<TR>
  <TD>TOGGLEHIGHLIGHT<br>PU</TD>
  <TD>toggles turtle highlighting<br />
    returns 0 if highlight off, 1 if on</TD>
</TR>
<TR>
  <TD>SETLANGUAGE<br>english</TD>
  <TD>changes language<br />
    returns 1</TD>
</TR>
<TR>
  <TD>HIDETURTLE<br>HT</TD>
  <TD>makes  turtle invisible<br />
    returns 0</TD>
</TR>
<TR>
  <TD>HOME</TD>
  <TD>moves  turtle to the center of the screen (0 0)<br />
    returns the distance turtle moved</TD>
</TR>
<TR>
  <TD>CLEARSCREEN<br>CS</TD>
  <TD>erases  turtle's trails and sends it to the home position<br />
    returns the distance turtle moved</TD>
</TR>
</TABLE>


<h3><a href="http://www.cs.duke.edu/courses/cps108/current/assign/03_slogo/index.php">SLogo</a>  Extended Commands</h3>


<h4>Required Commands</h4>
<table border="1">
<tbody><tr>
  <th>Command</th>
  <th>Description</th>
  <th>Example</th>
  </tr>
<tr>
  <td><code>SETBACKGROUND</code> <em>color_index</em><br>
      <code>SETBG</code> <em>color_index</em>
  </td>
  <td>sets background color of screen to that represented by <em>color_index</em><br>
    returns given <em>color_index</em></td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td><code>SETPENCOLOR</code> <em>color_index</em><br>
      <code>SETPC</code> <em>color_index</em>
  </td>
  <td>sets color of the pen to that represented by <em>color_index</em><br>
    returns given <em>color_index</em></td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td><code>SETPENSIZE</code> <em>pixels</em><br>
      <code>SETPS</code> <em>pixels</em>
  </td>
  <td>sets size of the pen to be <em>pixels</em> thickness<br>
    returns given <em>pixels</em></td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td><code>SETSHAPE</code> <em>shape_index</em><br>
      <code>SETSH</code> <em>shape_index</em>
  </td>
  <td>sets shape of turtle to that represented by <em>shape_index</em><br>
    returns given <em>shape_index</em></td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td><code>SETPALETTE</code> <em>color_index</em> <em>r</em> <em>g</em> <em>b</em></td>
  <td>sets color corresponding at given <em>color_index</em> to given <em>r</em> <em>g</em> <em>b</em> color values<br>
    returns given <em>color_index</em><br>
    note, color component values are nonnegative integers less than 256 specifying an amount of red, green, and blue </td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td><code>PENCOLOR<br>
  </code><code>PC</code></td>
  <td>returns the turtle's current color index</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td><code>SHAPE</code><br>
    <code>SH</code><em></em></td>
  <td>returns  the turtle's current shape index</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>STAMP</td>
  <td>"stamp" an image of the turtle in its current settings on the workspace display</td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td>CLEARSTAMPS</td>
  <td>remove all stamps that have been made</td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td>DOTIMES [ <em>variable</em> <em>limit</em> ]<br>
    [ <em>command(s)</em> ]</td>
  <td>runs the <em>commands</em> for each value specified in the range, i.e., from 0 up to (<em>limit</em> - 1). <br>
    note, <em>variable</em> is assigned to each succeeding value so that it can be accessed by the <em>commands</em></td>
  <td><code>DOTIMES [ :i 1800 ] <br>
    [ FD 10 RT :i + 1 ]</code></td>
  </tr>
<tr>
  <td>FOR [ <em>variable</em> <em>start end increment</em> ]<br>
    [ <em>command(s)</em> ]</td>
  <td>runs the <em>commands</em> for each value specified in the range, i.e., from start up to <em>end</em>, going by <em>increment</em>.<br>
    note, <em>variable</em> is assigned to each succeeding value so that it can be accessed by the <em>commands</em></td>
  <td><code>FOR [ :n 4 16 2 ] <br>
    [ FD 100 RT / 360 :n ]</code></td>
  </tr>
</tbody></table>
<h4>Expected Commands</h4>
<table border="1">
<tbody><tr>
  <th>Command</th>
  <th>Description</th>
  <th>Example</th>
</tr>
<tr>
  <td>ID</td>
  <td>returns the turtle's ID number</td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td><code>TELL</code> <code>[</code> <em>turtle(s)</em> <code>]</code></td>
  <td><p>sets <em>turtles</em> that will follow commands hereafter<br>
    returns last value in <em>turtles</em> list<em><br>
      </em>note, if turtle has not previously existed, it is created and placed at the home location<br>
    note, if more than one turtle is active, commands run return value associated with the last active turtle </p></td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>TELLEVEN<br>    <br></td>
  <td><p>sets <em>turtles</em> that will follow commands hereafter to the ones with even ID numbers<br>
    returns last turtle's ID value<em><br>
      </em>note, unlike the previous command, this one does not create any new turtles<br>
    note, if more than one turtle is active, commands run return value associated with the last active turtle </p></td>
  <td>&nbsp;</td>
  </tr>
<tr>
  <td>TELLODD</td>
  <td>sets <em>turtles</em> that will follow commands hereafter to the ones with odd ID numbers<br>
    returns last turtle's ID value<em><br>
  </em>note, unlike the previous command, this one does not create any new turtles<br>
    note, if more than one turtle is active, commands run return value associated with the last active turtle </td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td><code>ASK</code> <code>[</code> <em>turtle(s)</em> <code>]</code> <br>    
    <code>[</code><em>&nbsp;&nbsp;command(s)</em> <code>]</code></td>
  <td>tell <i>turtles</i> given in first list to run <em>commands</em> given in the second list<em><br>
    </em>returns result of last command run<br>
    note, after commands are run,  currently active list of turtles returns to that set by the last TELL command<br>
    note, if more than one turtle is active, commands run return value associated with the last active turtle </td>
  <td>&nbsp;</td>
</tr>
<tr>
  <td>( <em>command</em> <em>expression(s)</em> )</td>
  <td>allows <em>command</em> to take any number of <em>expressions</em> as parameter values<br>
    note, this syntax is legal for any command, but only makes sense for a few commands</td>
  <td>( SUM 1 2 3 4 5 )</td>
</tr>
</tbody></table>
<p>&nbsp;</p>
</div>



</body></html>